import swaggerJsdoc from 'swagger-jsdoc';
import { version } from '../../package.json';

const options: swaggerJsdoc.Options = {
  definition: {
    openapi: '3.0.0',
    info: {
      title: 'Express TypeScript API',
      version,
      description: '一个使用Express、TypeScript、TypeORM和MySQL构建的RESTful API服务',
      contact: {
        name: 'API Support',
        email: 'support@example.com'
      },
      license: {
        name: 'ISC',
        url: 'https://opensource.org/licenses/ISC'
      }
    },
    servers: [
      {
        url: 'http://localhost:3379',
        description: '开发服务器'
      },
      {
        url: 'https://api.yourdomain.com',
        description: '生产服务器'
      }
    ],
    components: {
      securitySchemes: {
        bearerAuth: {
          type: 'http',
          scheme: 'bearer',
          bearerFormat: 'JWT'
        },
        googleAuth: {
          type: 'oauth2',
          flows: {
            authorizationCode: {
              authorizationUrl: 'https://accounts.google.com/o/oauth2/v2/auth',
              tokenUrl: 'https://oauth2.googleapis.com/token',
              scopes: {
                'openid': 'OpenID Connect',
                'profile': '用户基本信息',
                'email': '用户邮箱'
              }
            }
          }
        }
      },
      schemas: {
        Error: {
          type: 'object',
          properties: {
            message: {
              type: 'string',
              description: '错误信息'
            },
            code: {
              type: 'string',
              description: '错误代码'
            },
            details: {
              type: 'object',
              description: '错误详情'
            }
          }
        },
        ValidationError: {
          type: 'object',
          properties: {
            message: {
              type: 'string',
              description: '验证错误信息'
            },
            errors: {
              type: 'array',
              items: {
                type: 'object',
                properties: {
                  field: {
                    type: 'string',
                    description: '字段名'
                  },
                  message: {
                    type: 'string',
                    description: '错误信息'
                  }
                }
              }
            }
          }
        }
      }
    },
    tags: [
      {
        name: 'Health',
        description: '健康检查端点'
      },
      {
        name: 'Users',
        description: '用户管理相关API'
      },
      {
        name: 'Auth',
        description: '认证相关API'
      },
      {
        name: 'Posts',
        description: '文章管理相关API'
      },
      {
        name: 'Payments',
        description: '支付相关API'
      }
    ]
  },
  apis: [
    './src/server.ts',
    './src/routes/*.ts',
    './src/controllers/*.ts',
    './src/entities/*.ts'
  ]
};

export const swaggerSpec = swaggerJsdoc(options); 